/*
 * TimerServicer.h
 *
 *   This is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2 of the License, or (at your option) any later version.
 *
 *   This software is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *  Created on: 2010-1-2
 *      Author: Huang Haiyang
 */

#ifndef TIMERSERVICER_H_
#define TIMERSERVICER_H_

#include <e32base.h>
#include "service\ClockSource.h"
#include "service\OnTickListener.h"

namespace service
	{
	
	class TimerService : public CBase
		{
	public:
		TimerService(OnTickListener* aListener);
		virtual ~TimerService();
		
	public:
		void Start();
		TUint32 Next();
		void Stop();
		void Reset();
		TBool Runing() const 
			{
			return iRuning;
			}
	protected:
		virtual void Beat();
		virtual void Synchronize();
		
	private:
		void ElapseBeat();
		void Kill();
		
		static TInt doTick(TAny* aCtx);
		
	private:
		CPeriodic      *iHeartbeat;
		OnTickListener *iOnTickListener;
		TUint32         iTimeInMills;
		TUint32         iLastTickCount;
		ClockSource     iClockSource;
		TBool           iRuning;
		};

	}

#endif /* TIMERSERVICER_H_ */
